// -----------------------------------------------------------------------------
// WEB B
// r2 group For 5N
// -----------------------------------------------------------------------------
$.fn.getR2data = function(_lotto_id,_gametype){
 var subid = $("div#rdiSubid input:radio:checked").val();
 $().disAreaObj();
 $.getJSON('op.php?op=xml_3d&fp=rate_3d&playtype=r2&lotto_id_3d='+_lotto_id+"&gametype="+_gametype+"&disk="+ $("select#slcDisk").val() + "&subid=" + subid ,function(ratedata){ 
      var dataLen = 0;
      var urlPre = "";
      var hrefStr = "";
      var disk = $("select#slcDisk").val();
      if(ratedata.errormsg != undefined){
        $("div#errormsg").addClass("error").text("No Rate data");
      }else{
          var subid = $("div#rdiSubid input:radio:checked").val();
          $("div#errormsg").text("Loading...");
          //$().creatRateDataTwoFace(ratedata.r17, '17',_gametype,disk);
          //$().creatRateDataTwoFace(ratedata.r18, '18',_gametype,disk);
          //$().creatRateDataTwoFace(ratedata.r19, '19',_gametype,disk);
          switch(subid){
            case '2': $().creatRateData(ratedata.r13_2, '13',_gametype,disk, subid); break;
            case '1': $().creatRateData(ratedata.r13_1, '13',_gametype,disk, subid); break;
            case '0': $().creatRateData(ratedata.r13_0, '13',_gametype,disk, subid); break;
          }
          
          $("div#errormsg").text("");
          $("div#mainPageData").show();
      }
      $().redisAreaObj();
  });
};


// create two face bet table data
$.fn.creatRateDataTwoFace = function(rdata, rnum,_gametype,disk, subid){
    var dataLen = rdata.number.length;
    urlPre = "op.php?op=member_3d&fp=bet_fast&palygroup=r2&bettype="+rnum+"&gametype="+_gametype+"&disk="+disk+"&subid="+ subid;
    for(i = 0; i < dataLen; i++){
    hrefStr = urlPre + "&num=" + rdata.number[i] + "&rate=" + rdata.rates[i];
    $("tbody#r"+rnum+" tr:nth-child(" +rdata.number[i] + ")>td:nth-child(2)").html('<a href="'+hrefStr+'" class=\"betRateNum\" target=\"leftFrame\">'+rdata.rates[i]+'</a>');}
    // change text or checkbox type
    var timebtnType = $("input:hidden#timebtnType").val();
    if(timebtnType == "checkbox"){
      $().timebtnTypeToCheckbox(); 
    }

};


// create table data
$.fn.creatRateData = function(rdata, rnum,_gametype,disk, subid){
    $("tbody#tbdr"+rnum).empty();
    dataLen = rdata.number.length;
    urlPre = "op.php?op=member_3d&fp=bet_fast&palygroup=r2&bettype="+rnum+"&gametype="+_gametype+"&disk="+disk+"&subid=" + subid;
    var tempTr = 5; // cols of each rows
    for(i = 0; i < dataLen; i++){
      
      hrefStr = urlPre + "&num=" + rdata.number[i] + "&rate=" + rdata.rates[i];
      if(i == 0){
        $('<tr class="td2" align=center><th class="title02_3d">'+rdata.number[i]+'</th><td class="betnum"><a href="'+hrefStr+'" class="betRateNum" target="leftFrame">'+rdata.rates[i]+'</a></td><td><input type="text" size="3" name="r'+rnum+'_'+rdata.number[i]+'" /></td></tr>').appendTo("tbody#tbdr"+rnum);
      }else if(i > 0 && i % tempTr == 0){
        $('<tr class="td2" align=center><th class="title02_3d">'+rdata.number[i]+'</th><td class="betnum"><a href="'+hrefStr+'" class="betRateNum" target="leftFrame">'+rdata.rates[i]+'</a></td><td><input type="text" size="3" name="r'+rnum+'_'+rdata.number[i]+'" /></td></tr>').appendTo("tbody#tbdr"+rnum);
      }else{
        $('<th class="title02_3d" align=center>'+rdata.number[i]+'</th><td class="betnum"><a href="'+hrefStr+'" class="betRateNum" target="leftFrame">'+rdata.rates[i]+'</a></td><td><input type="text" size="3" name="r'+rnum+'_'+rdata.number[i]+'" /></td>').appendTo("tbody#tbdr"+rnum+" tr:last");
      }
    }
    // change text or checkbox type
    var timebtnType = $("input:hidden#timebtnType").val();
    if(timebtnType == "checkbox"){
      $().timebtnTypeToCheckbox(); 
    }
};


// set 0-9 numbers
$.fn.getNum = function(num){
   var tmpName = "";
   var tmp1 = "";
   var tmp2 = "";
   var timebtnType = $("input:hidden#timebtnType").val();
   $("tbody#tbdr13 input:"+timebtnType).val(""); 
   $("tbody#tbdr13 input:"+timebtnType).filter(function(){
      tmpName = $(this).attr("name");
      tmp1 = tmpName.substr(4,1);
      tmp2 = tmpName.substr(5,1);
      if(tmp1 == tmp2){
        return false;
      }else if(tmp1==num || tmp2 == num){
        return true;
      }
   }).val("*");
   if(timebtnType=="checkbox"){
     $("tbody#tbdr13 input:checkbox[name^='r']:checked").removeAttr("checked");
     $("tbody#tbdr13 input:checkbox[name^='r'][value='*']").attr("checked","checked");
   }
};

// set pair numbers
$.fn.getPairNum = function(num){
   var tmpName = "";
   var tmp1 = "";
   var tmp2 = "";
   var timebtnType = $("input:hidden#timebtnType").val();
   $("tbody#tbdr13 input:"+timebtnType).val(""); 
   $("tbody#tbdr13 input:"+timebtnType).filter(function(){
      tmpName = $(this).attr("name");
      tmp1 = tmpName.substr(4,1);
      tmp2 = tmpName.substr(5,1);
      if(tmp1 == tmp2){
        return true;
      }else{
        return false;
      }
   }).val("*");
   
   if(timebtnType=="checkbox"){
     $("tbody#tbdr13 input:checkbox[name^='r']:checked").removeAttr("checked");
     $("tbody#tbdr13 input:checkbox[name^='r'][value='*']").attr("checked","checked");
   }
};